var prefix = ctx + "module/order"

$(function() {
	var columns = [{
            checkbox: true
        },
				{
			field : 'orderId', 
			title : '订单' 
		},
				{
			field : 'orderNum', 
			title : '订单号' 
		},
				{
			field : 'orderType', 
			title : '订单类型' , 
			formatter : function(value, row, index) {
				if (value == '0') {
					return '<span class="label label-primary">线上</span>';
				} else if (value == '1') {
					return '<span class="label label-success">线下</span>';
				}
			}
		},
				{
			field : 'customerClue.customerName', 
			title : '客户' 
		},
				{
			field : 'customerClue.customerSex', 
			title : '性别',
			formatter : function(value, row, index) {
				if (value == '0') {
					return '<span class="label label-primary">未知</span>';
				} else if (value == '1') {
					return '<span class="label label-success">男</span>';
				} else if (value == '2') {
					return '<span class="label label-danger">女</span>';
				}
			}
		},
				{
			field : 'deptName', 
			title : '部门' 
		},
				{
			field : 'salesUserName', 
			title : '业务员' 
		},
				{
			field : 'orderDispatch.protectTime', 
			title : '剩余保有时间' 
		},
		        {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
            	actions.push('<a class="btn btn-warning btn-sm ' + detailsFlag + '" href="#" title="详情" mce_href="#" onclick="details(\'' + row.orderId + '\')"><i class="fa fa-search"></i></a> ');
				actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="editFollow(\'' + row.orderId + '\')"><i class="fa fa-edit"></i></a> ');
				actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="发起结单" mce_href="#" onclick="Initiating(\'' + row.orderId + '\')"><i class="fa fa-hand-pointer-o"></i></a> ');
				return actions.join('');
            }
        }];
	var url = prefix + "/followList";
	$.initTable(columns, url);
});


/*订单-修改*/
function editFollow(orderId) {
    var url = prefix + '/editFollow/' + orderId;
    layer_showAuto("修改订单", url);
}

/* 待跟进订单-详情*/
function details(orderId) {
    var url = prefix + '/detailsFollow/' + orderId;
    layer_showAuto("待跟进订单详情", url);
}

/* 发起结单*/
function Initiating(orderId) {
    var url = prefix + '/initiatingOrder/' + orderId;
    layer_showAuto("发起结单", url);
}


/*跟单记录-新增*/
function add() {
    var url = prefix + '/followAdd';
    layer_showAuto("新增订单", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中订单吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("orderId");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
